<?php
ptaste();
require_once(dirname(__FILE__)."/interfaces.php");


class JEngDBXml implements IJXmlProducer
{
	public $doc=null;
	public $root=null;
	public $dbres=null;
	
	function __construct($xdbres,$rootname="result")
	{
	  $this->doc=new DOMDocument("1.0","utf8");
	  $this->doc->encoding="utf8";
	  $this->root=$this->doc->createElement($rootname);
	  $this->doc->appendChild($this->root);
	  $this->dbres=$xdbres;
	}
	
	function prepare()
	{
	}
	
	function render()
	{
	  $this->prepare();
	  while(($rw=$this->dbres->next()))
	  {
	    $xrw=$this->doc->createElement("row");
		for ($i=0;$i<$this->dbres->cols();$i++)
		{
		  $xrw->appendChild($this->doc->createElement($this->dbres->fieldName($i),$rw[$i]));
		}
		$this->root->appendChild($xrw);
	  }
	  return $this->doc;
	}
	
	static function s_render()
	{
	  $xdbres=func_get_arg(0);
	  $rootname="result";
	  if (func_num_args()>1)
	    $rootname=func_get_arg(1);
	  $obj=new JEngDBXml($xdbres,$rootname);
	  return $obj->render();
	}
}

?>